package com.sdry.product.waitingarea.controller;
import	java.util.ArrayList;
import java.util.List;

import com.sdry.basic.entity.Container;
import com.sdry.basic.entity.Material;
import com.sdry.common.BaseAPIMessageTypeEnum;
import com.sdry.common.BaseController;
import com.sdry.common.ResultAppInfo;
import com.sdry.exception.BizException;
import com.sdry.product.prod.entity.ResultAppList;
import com.sdry.product.waitingarea.service.StayContainerStareService;
import com.sun.glass.ui.Menu;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @Description APP端
 * @Author chenBin
 * @Date 2020-05-04 16:27
 * @Version 1.0
 **/
@RestController
@RequestMapping(value = "stayContainerStareApp")
public class StayContainerStareAppController extends BaseController {

    @Resource
    private StayContainerStareService stayContainerStareService;

    /**
     * 验证自定义编号是否存在
     */
    @RequestMapping(value = "/api/verificationNumber")
    public ResultAppInfo verificationNumber(String number) {
        logger.info("验证自定义编号是否存在","number = "+number);
        boolean boo = stayContainerStareService.verificationNumber(number);
        if (boo) {
            return getResultAppInfo("1",null,"");
        }else {
            return getResultAppInfo("0",null, BaseAPIMessageTypeEnum.A099.getName());
        }
    }

    /**
     * 查询成品库或者成品链的库存
     */
    @RequestMapping(value = "/api/queryProductContainer")
    public ResultAppInfo queryProductContainer(String type) {
        logger.info("查询成品库或者成品链的库存");
        List<ResultAppList<Material>> resultAppListList = stayContainerStareService.queryProductContainer(type);
        return getResultAppInfo("1",resultAppListList,"");
    }

    /**
     * 提交待发货区
     * @param json
     * @param userId
     * @return
     */
    @RequestMapping(value = "/api/addStayContainerStare")
    public ResultAppInfo addStayContainerStare(String json,String userId) {
        logger.info("提交待发货区 json = {}" +json);
        Long number = System.currentTimeMillis();
        List<String> strings = new ArrayList<>();
        strings.add(number.toString());
        try {
            stayContainerStareService.addStayContainerStare(json,userId,number.toString());
        }catch (BizException e) {
            return getResultAppInfo("0",null,e.getMessage());
        }catch (Exception e) {
            e.printStackTrace();
            return getResultAppInfo("0",null,BaseAPIMessageTypeEnum.A001.getName());
        }
        return getResultAppInfo("1",strings,"");
    }
}
